package com.yyx.app1.Data;

import android.util.Log;

import com.yyx.app1.MyApp;

import org.json.JSONObject;

/**
 * Created by yuexing on 2015/10/29.
 */
public class BOSSInfo {
    private String name;//真实姓名
    private String id;//账号  昵称
    private String portraitURL;//头像
    private String phone;//手机
    private String hospital;//所属医院
    private String sex;//性别

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getHospital() {
        return hospital;
    }

    public void setHospital(String hospital) {
        this.hospital = hospital;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPortraitURL() {
        return portraitURL;
    }

    public void setPortraitURL(String portraitURL) {
        this.portraitURL = portraitURL;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public static BOSSInfo setBossInfo( JSONObject response)
    {
        BOSSInfo bossInfo = new BOSSInfo();
        bossInfo.setName(assignment("name", response));
        bossInfo.setId(assignment("userName", response));
        bossInfo.setHospital(assignment("hospitalName", response));
        if (assignment("sex", response).equals("1"))
        {
            bossInfo.setSex("男");
        }
        else
        {
            bossInfo.setSex("女");
        }
        bossInfo.setPhone(assignment("phone", response));
        //头像
        StringBuffer str = new StringBuffer("http://www.cxlin.com/img_root/img_cuser/");
        String userimg = assignment("userimg", response);
        if (userimg == null)
        {
            bossInfo.setPortraitURL(testDate.portrait);
        }
        else {
            str.append(assignment("id", response)).append("/").append(userimg);
            bossInfo.setPortraitURL(str.toString());
        }
        return bossInfo;
    }

    private static String assignment(String key,JSONObject response) {
        String name=null;
        try {
            name = response.getString(key);
        }catch (Exception e)
        {
            Log.e("异常1511081317", e.toString());
        }
        if (name == null || name.isEmpty()) {
            name = "未知";
            if (key.equals("userimg"))
                name=null;
        }
        return name;
    }
}
